from queue import Queue, Empty
from common import CmdAiron, ApiRespBase


class Controler:
    def __init__(self):
        self.queue = Queue()
        self.humi = 0
        self.temp = 0

    def get_cmd(self, timeout):
        try:
            cmd = self.queue.get(timeout=timeout)
            return str(cmd)
        except Empty:
            resp = ApiRespBase.create_resp_ok(value="empty")
            return str(resp)

    def put_cmd(self, cmd):
        self.queue.put(cmd)

    def send_turn_on_cmd(self):
        cmd = CmdAiron.create_cmd_airon_on()
        self.put_cmd(cmd)

    def send_turn_off_cmd(self):
        cmd = CmdAiron.create_cmd_airon_off()
        self.put_cmd(cmd)

    def record_info(self, humi, temp):
        self.humi = humi
        self.temp = temp

    def get_airconf_info(self):
        return self.humi, self.temp